package com.wyy.dao.impl;

import com.wyy.bean.Menu;
import com.wyy.dao.DBUtils;
import com.wyy.dao.MenuDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName MenuDaoImpl
 * @Description //TODO
 * @Author wky
 * @Date 2021/9/28 20:52
 * @Version 1.0
 **/
public class MenuDaoImpl extends DBUtils implements MenuDao {
    @Override
    public List<Menu> getMenuList() {

        List<Menu> menus = new ArrayList<>();

        try {
            String sql = "select * from menu";
            resultSet = query(sql, null);
            while (resultSet.next()){
                Menu menu = new Menu();
                menu.setMenuId(resultSet.getInt("menuid"));
                menu.setMenuName(resultSet.getString("menuname"));
                menu.setUpmenuId(resultSet.getInt("upmenuid"));
                menu.setDesc(resultSet.getString("desc"));
                menu.setUrl(resultSet.getString("url"));
                menus.add(menu);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }

        return menus;
    }
}
